# -*- mode: ruby -*-
# vi: set ft=ruby :

boxes = [
  { :name => :nimbus, :ip => '192.168.33.100', :cpus =>2, :memory => 512 },
  { :name => :supervisor1, :ip => '192.168.33.101', :cpus =>4, :memory => 1024 },
  { :name => :supervisor2, :ip => '192.168.33.102', :cpus =>4, :memory => 1024 },
  { :name => :zookeeper1, :ip => '192.168.33.201', :cpus =>1, :memory => 512 },
]


Vagrant.configure("2") do |config|
  boxes.each do |opts|
  	config.vm.define opts[:name] do |config|
      config.vm.box = "precise64"
      # http://dl.dropbox.com/u/1537815/precise64.box
   	  config.vm.box_url = "http://files.vagrantup.com/precise64.box"
      config.vm.network :hostonly, opts[:ip]
      config.vm.hostname = "storm.%s" % opts[:name].to_s
      config.vm.share_folder "v-data", "/vagrant_data", "./data", :transient => false

      config.vm.customize ["modifyvm", :id, "--memory", opts[:memory]]
      config.vm.customize ["modifyvm", :id, "--cpus", opts[:cpus] ] if opts[:cpus]

      config.vm.provision :shell, :inline => "hostname storm.%s" % opts[:name].to_s
	  config.vm.provision :shell, :inline => "cp -fv /vagrant_data/hosts /etc/hosts"
	  config.vm.provision :shell, :inline => "apt-get update"
	  config.vm.provision :shell, :inline => "apt-get --yes --force-yes install puppet"
	  
	  if File.exist?("./data/jdk-6u35-linux-x64.bin") then
		config.vm.provision :puppet do |puppet|
		  puppet.manifests_path = "manifests"
		  puppet.manifest_file = "jdk.pp"
		end
	  end
	  
	  config.vm.provision :puppet do |puppet|
	    puppet.manifests_path = "manifests"
	    puppet.manifest_file = "provisioningInit.pp"
	  end

	  # Ask puppet to do the provisioning now.
	  config.vm.provision :shell, :inline => "puppet apply /tmp/storm-puppet/manifests/site.pp --verbose --modulepath=/tmp/storm-puppet/modules/ --debug"	

    end
  end
end